﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Omes.Model;
using Omes.Services;
using Page = Omes.Model.Page;

namespace Omes.Admin.ContentManage
{
    public partial class MenuList : System.Web.UI.Page
    {
        public List<Omes.Model.Page> Pages = new List<Page>();

        public int PagesCount
        {
            get
            {
                if (Pages.Count < ShowRows)
                {
                    return 1;
                }
                else
                {
                    return Pages.Count / ShowRows + 1;
                }
            }
        }

        public List<Omes.Model.Page> CurrentPages = new List<Page>();

        public static int ShowRows = 3;


        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!Page.IsPostBack)
            //{
                Omes.Services.DbServer db = new DbServer();
                Pages = db.GetAllPages();
                int numPage = Convert.ToInt32(Request.QueryString["numPage"]);
                if (numPage > 0)
                {
                    numPage = numPage - 1;
                }
                CurrentPages = new List<Page>();
                for (int i = numPage * ShowRows; i < (numPage * ShowRows + ShowRows); i++)
                {
                    if (Pages.Count > i)
                    {
                        CurrentPages.Add(Pages[i]);
                    }
                }

            //}
            //else
            //{
                
            //}
        }

        public PageType GetPageType(int typeId)
        {
            PageType type = new PageType();
            DbServer db = new DbServer();
            type = db.GetPageType(typeId);
            return type;
        }

        public Page GetPage(int id)
        {
            Model.Page page = new Page();
            if (id <= 0)
            {
                page.PageName = "顶级页面";
            }
            else
            {
                page = Pages.Where(o => (o.Id == id)).FirstOrDefault();
            }
            return page;
        }
    }
}